package com.sunday.android.fangdaifu.bukong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sunday.android.fangdaifu.bukong.R;
import com.sunday.android.fangdaifu.bukong.entity.HouseItem;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘涛 on 2017/11/7.
 */

public class HouseEquipmentAdapter extends BaseAdapter {

    private List<HouseItem> datas=new ArrayList<>();
    private Context mContext;
    public HouseEquipmentAdapter(Context context) {
        this.mContext = context;
    }
    public HouseEquipmentAdapter(Context context, List<HouseItem> datas) {
        this.datas = datas;
        this.mContext = context;
    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_equipment_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        HouseItem item=datas.get(position);
        viewHolder.name.setText(item.getPlantNo());
        viewHolder.address.setText(item.getAddress());
        viewHolder.equipAddr.setText(item.getPosition());
        viewHolder.nowValue.setText(item.getNowValue());

        return convertView;
    }

    public void setDatas(List<HouseItem> datas) {
        this.datas = datas;
    }


    static class ViewHolder {
        @Bind(R.id.name)
        TextView name;
        @Bind(R.id.now_value)
        TextView nowValue;
        @Bind(R.id.address)
        TextView address;
        @Bind(R.id.equip_addr)
        TextView equipAddr;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}

